#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <algorithm>
#include <cmath>
#define int long long
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int>arr(n + 10);
    vector<int>brr(n + 10);
    vector<int>ranks(n + 10);

    for(int i = 1; i <= n; i ++) cin >> arr[i];
    for(int i = 1; i <= n; i ++) cin >> brr[i];
    for(int i = 1; i <= n; i ++) 
    {
        int x;
        cin >> x;
        ranks[x + 1] = i;
    }
    int ansl = 0;
    int ansr = 0x3f3f3f3f;
    int flag = 0;
    for(int i = n - 1; i >= 1; i --)
    {
        auto x = arr[ranks[i]],y = brr[ranks[i]];
        auto u = arr[ranks[i + 1]],v = brr[ranks[i + 1]];

        if(y == v)
        {
            if(x <= u) 
            {
                flag = 1;
                break;
            } 
            else continue;
        }

        if(y < v)
        {   
            ansr = min(ansr,(u - x + y - v + 1)/(y - v) - 1);
        }
        else if(y > v)
        {
            ansl = max(ansl,(int)(floor((1.0 * u - x) / (y - v)) + 1));
        }
    }
    if(flag == 0 && ansl <= ansr) cout << ansl << endl;
    else cout << -1 << endl;
}

signed main()
{
    int t = 1;
    cin >> t;
    while(t --)
    {
        solve();
    }
}
